﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleData.ObjectModel.Types
{
	public struct YesNo
	{
		private bool? bit;

		
		public override bool Equals( object obj )
		{
			return base.Equals( obj );
		}

		public override int GetHashCode()
		{
			if ( this.bit.HasValue )
				return this.bit.Value.GetHashCode();
			else
				return 0;
		}

		public override string ToString()
		{
			return this.bit.ToString();
		}

		public static implicit operator bool( YesNo x )
		{
			return ( x.bit ?? false );
		}

		#region [ Logical Operators Overload ]

		public static bool operator &(YesNo x, YesNo y)
		{
			return ( x.bit ?? false ) & ( y.bit ?? false );
		}

		public static bool operator |(YesNo x, YesNo y )
		{
			return ( x.bit ?? false ) | ( x.bit ?? false );
		}

		public static bool operator !(YesNo x )
		{
			return !( x.bit ?? false );
		}

		public static bool operator ==(YesNo x, YesNo y)
		{
			return ( x & y )
				|| ( !x && !y );
		}

		public static bool operator !=(YesNo x, YesNo y )
		{
			return ( x && !y ) || ( !x && y );
		}

		public static bool operator true(YesNo x )
		{
			return x.bit ?? false;
		}

		public static bool operator false(YesNo x)
		{
			return x.bit ?? false;
		}

		#endregion

	}
}
